package com.atguigu.test.dacahngmainshitidierji.java8;


import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 2 * @Author: madonghui
 * 3 * @Date: 2020/11/23 13:33
 * 4
 */
public class OptionalDemo {
    public static void main(String[] args) {
        String str = null;
        //Optional.of(str);    这个方法只能放非空对象
        //Optional.ofNullable(str);

        Optional<String> str1 = Optional.ofNullable(str);
        System.out.println(str1);
        if (str1.isPresent()){
            //str1.get()  如果这个方法如果返回null的话会抛出没有元素异常，有的话直接返回
            System.out.println(str1.get());
        }
        List<Integer> integers = Arrays.asList(1,1,1, 2,2, 3,3, 4, 5, 6, 7, 8, 9, 10);
        System.out.println(integers.stream().distinct().count());
        System.out.println(integers.stream().distinct().sorted().collect(Collectors.toList()));
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1);
        Integer integer = integers.stream().findFirst().get();
        System.out.println(integer);

    }
}
